package org.streamerstudio.ui.properties;

import org.eclipse.emf.edit.provider.ComposedAdapterFactory;
import org.eclipse.emf.edit.ui.provider.AdapterFactoryLabelProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import org.streamerstudio.model.gstreamer.registry.GstObject;
import org.streamerstudio.model.gstreamer.registry.provider.RegistryItemProviderAdapterFactory;

public class TitleBarLabelProvider extends LabelProvider {

	private AdapterFactoryLabelProvider provider;
	
	public TitleBarLabelProvider(){
		ComposedAdapterFactory adapterFactory = new ComposedAdapterFactory(ComposedAdapterFactory.Descriptor.Registry.INSTANCE);
		adapterFactory.addAdapterFactory(new RegistryItemProviderAdapterFactory());
		provider = new AdapterFactoryLabelProvider(adapterFactory);
	}
	
	@Override
	public Image getImage(Object object) {
		if (object instanceof IStructuredSelection){
			Object element = ((IStructuredSelection)object).getFirstElement();
			if (GstObject.class.isAssignableFrom(element.getClass())){
				return provider.getImage(element);
			}
		}
		return super.getImage(object);
	}

	@Override
	public String getText(Object object) {
		if (object instanceof IStructuredSelection){
			Object element = ((IStructuredSelection)object).getFirstElement();
			if (GstObject.class.isAssignableFrom(element.getClass())){
				return provider.getText(element);
			}
		}
		return super.getText(object);
	}

}
